#! /usr/bin

leftNum=0;
rightNum=0;

# 操作数输入提示信息
printf_usage()
{
    echo "Please input an interger num！";
}

# 读入第一个操作数
# read 指令为从键盘中读取数据，-p为输出提示信息
read -p "Please input the left operator num:"  leftNum

# 检查输入的参数是否争取，即是否之包含0~9的数字
# 检测方法：通过sed指令，将所有数字替换为空，查看最后结果是否为空
# 如果为空，那说明输入的结果有非数字字符，输出提示信息
if [ -n "`echo $leftNum | sed 's/[0-9]//g'`" ]
    then
        print_usage
        exit 1
fi

# 输入操作符
read -p "Please input your operator:"  operator

# 判断操作符是否为加减乘除其中之一
if [ ${operator} != "+" ] && [ ${operator} != "-" ] && [ ${operator} != "*" ] && [ ${operator} != "/" ]
    then
        echo "The operator must be + or - or * or /"
        exit 2
fi

# 输入第二个操作符
read -p "Please input the right operator num:"  rightNum

# 检查第二个操作数是否合法
if [ -n "`echo ${rightNum} | sed 's/[0-9]//g'`" ]
    then 
        print_usage
        exit 3
fi

echo "${leftNum} ${operator} ${rightNum} = $((${leftNum}${operator}${rightNum}))"